package sdk

import (
	ns "github.com/nats-io/nats.go"
	"log"
	"os"
)


//
var (
	natUrl    = "nats://10.4.60.84:4222"
	//topicOld  = "wsgateway.%s"
	//topic     = "wsgw.message.service.%s"
	//serviceId = "serviceId"
)

type Message struct {
	Header map[string]string `json:"header"`
	Body   []byte           `json:"body"`
}

type Body struct{
	WsIds []string  `json:"WsIds"`
	Data   []byte    `json:"data"`
}

//var contentType = "application/json"

var(
	conn *ns.Conn
)

func GetNatsObj() *ns.Conn {
	 return conn
}

func InitNats() (err error) {
	var natsUrl string
	if os.Getenv("NATS_URL") != "" {
		natsUrl = os.Getenv("NATS_URL")
	} else {
		natsUrl = "nats://10.0.0.203:30222"
	}
	log.Printf("nats url: %v", natsUrl)
	conn, err = ns.Connect(natsUrl)
	if err != nil {
		log.Fatalf("nate connection error : %v", err)
		return err
	}

	return

}



